package main

import (
	"fmt"
	"reflect"
)

type student struct {
	Name   string
	Number int
	Height uint
	Weight float64
}

func (s student) Info() {
	fmt.Printf("Name:\t%s\n", s.Name)
	fmt.Printf("Number:\t%03d\n", s.Number)
	fmt.Printf("Height:\t%d cm\n", s.Height)
	fmt.Printf("Weight:\t%.2f kg\n", s.Weight)
}

func (s *student) SetHeightWeight(h uint, w float64) {
	s.Height = h
	s.Weight = w
}

func main() {
	s1 := student{"Jimmy", 1, 170, 65.5}
	st1 := reflect.TypeOf(s1)
	n1, ok := st1.MethodByName("Info")
	fmt.Printf("%#v, %v\n", n1, ok)
	n2, ok := st1.MethodByName("SetHeightWeight")
	fmt.Println(n2, ok)
	sv1 := reflect.ValueOf(s1)
	v1 := sv1.MethodByName("Info")
	fmt.Println(v1)
	v2 := sv1.MethodByName("SetHeightWeight")
	fmt.Println(v2)
	fmt.Println(v2.String())
	fmt.Println(v2.Kind() == reflect.Invalid)
}
/* 输出结果：
reflect.Method{Name:"Info", PkgPath:"", Type:(*reflect.rtype)(0xc00004a060), Func:reflect.Value{typ:(*reflect.rtype)(0xc00004a060), ptr:(unsafe.Pointer)(0xc000006040), flag:0x13}, Index:0}, true
{  <nil> <invalid Value> 0} false
0x85ff60
<invalid reflect.Value>
<invalid Value>
true
*/
